<!DOCTYPE html>
<!--[if IE 8]> <html lang="en" class="ie8 no-js"> <![endif]-->
<!--[if IE 9]> <html lang="en" class="ie9 no-js"> <![endif]-->
<!--[if !IE]><!-->
<html lang="en" class="no-js">
<!--<![endif]-->
<head>
<meta charset="utf-8">
<title>SMM撮合系统--订单管理</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta content="width=device-width, initial-scale=1" name="viewport">
<meta content="" name="description">
<meta content="" name="author">
<link href="${request.getContextPath()}/Public/assets/admin/css/css.css" rel="stylesheet" type="text/css">
<link href="${request.getContextPath()}/Public/assets/global/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<link href="${request.getContextPath()}/Public/assets/global/plugins/simple-line-icons/simple-line-icons.min.css" rel="stylesheet" type="text/css">
<link href="${request.getContextPath()}/Public/assets/global/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css">
<link href="${request.getContextPath()}/Public/assets/global/plugins/uniform/css/uniform.default.css" rel="stylesheet" type="text/css">
<link href="${request.getContextPath()}/Public/assets/global/css/components-rounded.css" id="style_components" rel="stylesheet" type="text/css">
<link href="${request.getContextPath()}/Public/assets/global/css/plugins.css" rel="stylesheet" type="text/css">
<link href="${request.getContextPath()}/Public/assets/admin/css/layout.css" rel="stylesheet" type="text/css">
<link href="${request.getContextPath()}/Public/assets/admin/css/themes/default.css" rel="stylesheet" type="text/css" id="style_color">
<link href="${request.getContextPath()}/Public/assets/admin/css/custom.css" rel="stylesheet" type="text/css">
<link href="${request.getContextPath()}/Public/assets/global/plugins/bootstrap-datepicker/css/bootstrap-datepicker.min.css" rel="stylesheet" type="text/css">
<link href="${request.getContextPath()}/Public/assets/admin/css/common.css" rel="stylesheet" type="text/css">
<link rel="shortcut icon" href="${request.getContextPath()}/Public/favicon.ico">
<link href="${request.getContextPath()}/Public/css/client.css" rel="stylesheet" type="text/css">
<link href="${request.getContextPath()}/Public/css/page1.css" rel="stylesheet" type="text/css">
<link href="${request.getContextPath()}/Public/assets/global/css/kkpager.css" rel="stylesheet" type="text/css">
<script>BASE_URL = '${request.getContextPath()}'</script>
<link href="${request.getContextPath()}/Public/css/customerDetail.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="${request.getContextPath()}/Public/My97DatePicker/WdatePicker.js"></script>
<style type="text/css">
body{margin:0;padding:0;}
 /*div_Import */
#div_Import{position:fixed;z-index:999;width:600px;height:400px;border:1px solid #ccc;background:#efefef;display:none;overflow:auto;}
#div_Import .tit{background:#ddd;display:block;height:15px;}
#div_Import .tit i{float:right;line-height:15px;padding:0 8px;cursor:pointer;}
</style>

</head>

<body class="page-header-top-fixed">
<div id="div_Import">
	<div class="tit"><i class="close">关闭</i></div>
	<p style="margin-left:50PX;">请选择合同文件：</p>
	<input style="margin-left:90PX;" type="file" id="fileData" name="fileData" />
	<input type="hidden" id="ccc"> 
	<input style="margin-left:80%;" type="button" class="btn green" value="上传" onclick="submitContacter()"/>
	<p id="errorInfo" style="width:80%;margin-left:50PX;"></p>	
</div>
<!--头部信息结束 -->
<div class="page-header">
	<!--头部开始-->
	<#include "/include/top.html" />
	<!-- 头部信息结束 -->


	<!-- 头部菜单开始 -->
	<#include "/include/top_menu.html" />
	<!-- 头部菜单结束 -->
</div>
<!-- END HEADER -->


<!-- BEGIN PAGE CONTAINER -->
<div class="page-container">
	<!-- 内容开始 -->
	<div class="page-content">
		<div class="container-fluid">
			<!-- 当前位置提示结束 -->
			<!-- 当前位置提示开始 -->
			<ul class="page-breadcrumb breadcrumb">
				<li>
					<a href="#">首页</a><i class="fa fa-circle"></i>
				<li class="active">
					 撮合管理<i class="fa fa-circle"></i>
				<li class="active">
					 订单管理
			</ul>
			<div class="row margin-top-10">
				<!--位置提示结束  -->
				<div class="col-md-12">
				     <div class="portlet light bordered">
					    <div class="portlet-body">
						 <form id="frm1" method="post">
					    	<div class="row">
							  <div style="overflow:hidden; width: 62%;">
							   <div style="width:20%;float:left;margin-left:15px;">
								<select class="form-control" id="attribute" name="attribute" onblur="selectColumn();">${qc.attribute!""}
											<option value="-1"  <#if qc.attribute?default("")="-1">selected</#if>>--选择筛选条件--</option>
											<option value="b.orderCode" <#if qc.attribute?default("")="b.orderCode">selected</#if>>订单编号</option>
											<option value="getItemNameById(b.itemid)" <#if qc.attribute?default("")="getItemNameById(b.itemid)">selected</#if>>产品</option>
<!-- 											<option>品牌</option> -->
										    <option value="b.createdAt" <#if qc.attribute?default("")="b.createdAt">selected</#if>>成交时间</option>
											<!-- <option value="a.price" <#if qc.attribute?default("")="a.price">selected</#if>>价格</option>-->
											<!-- <option value="a.quantity" <#if qc.attribute?default("")="a.quantity">selected</#if>>数量</option>-->
											<option value="v.name" <#if qc.attribute?default("")="v.name">selected</#if>>地区</option>
											<option value="getUserNameById(b.createdBy)" <#if qc.attribute?default("")="getUserNameById(b.createdBy)">selected</#if>>撮合人</option>
											<option value="getCompanyNameById(b.sellId)" <#if qc.attribute?default("")="getCompanyNameById(b.sellId)">selected</#if>>卖方</option>
											<option value="getCompanyNameById(b.buyId)" <#if qc.attribute?default("")="getCompanyNameById(b.buyId)">selected</#if>>买方</option> 			
								</select>
							</div>
							<div  style="width:10%;float:left; margin-left:15px;">
								<select class="form-control" id="operator" name="operator">
									  <option value="1" <#if qc.operator?default("")="1">selected</#if>>包含</option>
							          <option value="2" <#if qc.operator?default("")="2">selected</#if>>不包含</option>
							          <option value="3" <#if qc.operator?default("")="3">selected</#if>>等于</option>
							          <option value="4" <#if qc.operator?default("")="4">selected</#if>>不等于</option>
							          <option value="5" <#if qc.operator?default("")="5">selected</#if>>开始字符</option>
							          <option value="6" <#if qc.operator?default("")="6">selected</#if>>结束字符</option>
							          <option value="7" <#if qc.operator?default("")="7">selected</#if>>为空</option>
							          <option value="8" <#if qc.operator?default("")="8">selected</#if>>不为空</option>
								</select>
							</div>
							<div class="col-md-3">
								<input type="text" class="form-control" id="content" name="content" value="${qc.content!''}">
							</div>
							<div class="col-md-2">
									<button  class="btn green">
										<i class="fa fa-search"></i> 搜索 
									</button>
								</div>
							</div>

						</div>
					</form>
						
						<div class="table-scrollable">
				          		<table class="table table-striped table-bordered table-advance table-hover ttTbl" id="myTable" >
						          	<thead>
										<tr>		
											<th>订单编号</th>
											<th>产品</th>
											<#if attrs??>
												<#list attrs as attr>
												<th>
													${attr.name}
												</th>
												</#list>
											</#if>

											<th>价格</th>
											<th>数量</th>
											<th>地区</th>
											<th>成交时间</th>
											<th>撮合人</th>
											<th>卖方</th>
											<th>买方</th>
											<th width="20%">操作</th>
										</tr>
								</thead>
								<tbody>
										<#list list as order>
									       <tr <#if order.orderStatus==1> style="color: #A8A8A8;" </#if>>
												<td>${order.orderCode?if_exists}</td>
												<td>
												<#list order.subOrderList as sub>
															<#list sub.commodityAttrList as Value> 
																<#if Value_index==0> 
																	${Value.commodityName?if_exists}</br>
																</#if>
															</#list>
												</#list>
												</td>
												<#list attrs as itemAttr>
													<td>
														<#list order.subOrderList as sub>
															<#assign flag=true/>  
															<#list sub.commodityAttrList as Value>
																<#if Value?size gt 0>
																	 <#if itemAttr.name == Value.attrName >
																	 <#assign flag=false/>
																		${Value.attrValue!''}
																		</br>
																	 </#if>
																</#if>
															</#list>
															<#if  flag>
																&nbsp;
																<br>
															</#if>
														</#list>
													</td>
												</#list>
												
												<td>
												<#list order.subOrderList as suborder>
													${suborder.price?if_exists}
												<br>
												</#list>
												</td>
												<td>
												<#list order.subOrderList as suborder>
													${suborder.quantity?c}
													<#if suborder.unit==0>
													吨
												</#if>
												<#if suborder.unit==1>
													千克
												</#if>
													<br>
												</#list>
												</td>
												<td>${order.wareNm?if_exists}</td>
												<td>
												<#if   (order.createdAt)??>${(order.createdAt)?string("yyyy-MM-dd")}</#if>
												</td> 
												<td>${order.createdByName?if_exists}</td>
												
												<td>${order.sellCompanyNm?if_exists}   </td> 
												<td>${order.buyCompanyNm?if_exists}  <#if order.confirmStatus==1><br>(未确认合同)</#if></td> 
												
												
												<!--操作按钮  -->
												<td >
												<a class="btn btn-xs green" href="javascript:orders_details(${order.id})">查看订单</a>
												<#if order.orderStatus==0 && (order.confirmStatus = 0 || order.confirmStatus = 2)>
													<a class="btn btn-xs green"   href="${request.getContextPath()}/order/updateOrderStatus.do?id=${order.id}&&status=1">
														确认交收
													</a>
												</#if>
															
												<#if order.orderStatus ==0>
													<a class="btn btn-xs green"   onclick="div_Import(${order.id})" >合同上传</a>
												</#if>
												<#if order.confirmStatus gt 0>
													<a class="btn btn-xs green"   href="${request.getContextPath()}/contract/generateContractByTemplate.do?orderId=${order.id}">查看合同</a> 
												</#if>
												<#if order.contract?? && order.contract.filePath??>
													<a class="btn btn-xs green"   href="javascript:viewContract(${order.id})">合同下载</a>
												</#if>
												<#if order.orderStatus == 1>
													<a class="btn btn-xs grey" href="javascript:void(0)">已交收</a>
												</#if>
												<#if order.orderStatus == 2>
													<a class="btn btn-xs grey" href="javascript:void(0)">已撤销</a>
												</#if>
												 </td>
											</tr>
										</#list>
								  </tbody>
								</table>
						 	</div>		
						  	<div>
						          	<div style="width:80%;margin:0 auto;">
										<div id="kkpager"></div>
										<input type="hidden" value="${totalPage}" id="totalPage">
										<input type="hidden" value="${totalRecords}" id="totalRecords">
									</div>
								</div>
						    </div>
					    </div>
					</div>
				</div>
		</div>
</div>
</div>


					
<!-- END PAGE CONTAINER -->



<!-- 底部开始 -->
<#include "/include/foot.html" />
<!-- 底部结束 -->

<!--[if lt IE 9]>
<script src="${request.getContextPath()}/Public/assets/global/plugins/respond.min.js"></script>
<script src="${request.getContextPath()}/Public/assets/global/plugins/excanvas.min.js"></script> 
<![endif]-->
<script src="${request.getContextPath()}/Public/assets/global/plugins/jquery.min.js" type="text/javascript"></script>
<script src="${request.getContextPath()}/Public/assets/global/plugins/jquery-migrate.min.js" type="text/javascript"></script>
<script src="${request.getContextPath()}/Public/assets/global/plugins/jquery-ui/jquery-ui.min.js" type="text/javascript"></script>
<script src="${request.getContextPath()}/Public/assets/global/plugins/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
<script src="${request.getContextPath()}/Public/assets/global/plugins/bootstrap-hover-dropdown/bootstrap-hover-dropdown.min.js" type="text/javascript"></script>
<script src="${request.getContextPath()}/Public/assets/global/plugins/jquery-slimscroll/jquery.slimscroll.min.js" type="text/javascript"></script>
<script src="${request.getContextPath()}/Public/assets/global/plugins/jquery.blockui.min.js" type="text/javascript"></script>
<script src="${request.getContextPath()}/Public/assets/global/plugins/jquery.cokie.min.js" type="text/javascript"></script>
<script src="${request.getContextPath()}/Public/assets/global/plugins/uniform/jquery.uniform.min.js" type="text/javascript"></script>
<script src="${request.getContextPath()}/Public/assets/global/plugins/jquery-notific8/jquery.notific8.min.js"></script>
<script src="${request.getContextPath()}/Public/assets/global/plugins/bootstrap-datepicker/js/bootstrap-datepicker.js" type="text/javascript"></script>
<script src="${request.getContextPath()}/Public/assets/global/scripts/metronic.js" type="text/javascript"></script>
<script src="${request.getContextPath()}/Public/assets/admin/scripts/layout.js" type="text/javascript"></script>
<script src="${request.getContextPath()}/Public/assets/global/plugins/kkpager.min.js" type="text/javascript"></script>
<script src="${request.getContextPath()}/Public/assets/admin/scripts/commonUtils.js" type="text/javascript"></script>
<script src="${request.getContextPath()}/Public/assets/admin/scripts/tc.min.js" type="text/javascript"></script>
<script src="${request.getContextPath()}/Public/assets/admin/scripts/ajaxfileupload.js" type="text/javascript"></script>
<script>

function chexiao(url){

	var a=confirm("该操作会直接影响双方订单，且不可恢复，是否确认搞通单？");
	if(a){
		window.location=url;
	}
}

jQuery(document).ready(function() {
	   Metronic.init(); // init metronic core componets
	   Layout.init(); // init layout
	   CommonUtils.checkInit();
	});
	
	selectColumn();
	recordDate();
	//初始化日期
	function recordDate() {
		var nowDate = new Date();
        //$('#date-picker').attr("date-date",nowDate.getFullYear()+"/"+parseInt(nowDate.getMonth()+1)+"/"+nowDate.getDate());
        $('.date-picker').datepicker({
    	    autoclose: true	   
    	});
	}
	function selectColumn() {
		var value = $("#attribute").val();
		if (value == "b.createdAt") {
			$('#content').bind("click", function(){WdatePicker();});
		} else {
			$('#content').unbind("click");
		}
	}

	function    div_Import(orderid){
		$("#ccc").val(orderid);
		orderid=orderid;
		$("#errorInfo").html("");
		popWin("div_Import");
	
	}
	//提交excel上传的form表单
	function submitContacter(){
		var fileName=$("#fileData").val();
		if(fileName.length==0){
			alert("请选择需导入的文件！")
			return;
		}
		$.ajaxFileUpload({
	        url: "${request.getContextPath()}/order/contacterUpload.do?id="+$("#ccc").val(), //用于文件上传的服务器端请求地址
	        secureuri: false, //是否需要安全协议，一般设置为false
	        fileElementId: "fileData", //文件上传域的ID
	        dataType: "JSON", //返回值类型 一般设置为json
	        success: function (data, status){  //服务器成功响应处理函数
	        	CommonUtils.succModal2("", data, "${request.getContextPath()}/order/ordersList.do");
	        },
	        error: function (data, status, e) { //服务器响应失败处理函数
	            alert(e);
	        }
          }
      );
	}
	function orders_details(orderId){
		if(orderId||orderId==0){
			CommonUtils.editModal(BASE_URL + "/customerDetail/orderRecord/orderDetail.do?orderId="+orderId, 800);
		}
	}
	//初始化分页插件
	function getParameter(name) { 
		var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)"); 
		var r = window.location.search.substr(1).match(reg); 
		if (r!=null) return unescape(r[2]); return null;
	}
	
	//init
	$(function(){
		
		var totalPage = $('#totalPage').val();
		var totalRecords = $('#totalRecords').val();
		var attribute = $('#attribute').val();
		var operator = $('#operator').val();
		var content = $('#content').val();
		
		var pageNo = getParameter('pno');
		if(!pageNo){
			pageNo = 1;
		}
		//生成分页
		//有些参数是可选的，比如lang，若不传有默认值
		kkpager.generPageHtml({
			pno : pageNo,
			//总页码
			total : totalPage,
			//总数据条数
			totalRecords : totalRecords,
			getLink : function(n){
				return this.hrefFormer + this.hrefLatter + "?pno="+n+"&attribute="+attribute+"&operator="+operator+"&content="+encodeURI(encodeURI(content));
			}	
		});
	});
	
	
	//合同下载
	function viewContract(orderId) {

		CommonUtils.editModal(
				'${request.getContextPath()}/order/tocontacterDownload.do?orderId='
						+ orderId, 600);

	}
</script>
</body>
</html>